package com.tl.commonlibrary.ui.web.bean;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

import java.io.Serializable;

/**
 * Created by JongSung on 17/1/19.
 */

public class Active implements Serializable {
    public static final int ACTIVE_TYPE_SECTOR = 1;//热门板块
    public static final int ACTIVE_TYPE_RANK_LIST = 2;//排行榜
    public static final int ACTIVE_TYPE_OPEN_ACCOUNT = 3;//开户
    public static final int ACTIVE_TYPE_PHONE_NUMBER = 4;//客服电话
    public int type;
    /**
     * 不同类型{@link #type}返回的data类型不一样，需要实时gson解析
     */
    private JsonElement body;

    private Sector sector;
    private RankList rankList;
    private OpenAccount openAccount;
    private Phone phone;

    public boolean isSector() {
        return type == ACTIVE_TYPE_SECTOR;
    }

    public Sector getSector() {
        if (sector == null) {
            sector = new Gson().fromJson(body, Sector.class);
        }
        return sector;
    }

    public boolean isRankList() {
        return type == ACTIVE_TYPE_RANK_LIST;
    }

    public RankList getRankList() {
        if (rankList == null) {
            rankList = new Gson().fromJson(body, RankList.class);
        }
        return rankList;
    }

    public boolean isOpenAccount() {
        return type == ACTIVE_TYPE_OPEN_ACCOUNT;
    }

    public OpenAccount getOpenAccount() {
        if (openAccount == null) {
            openAccount = new Gson().fromJson(body, OpenAccount.class);
        }
        return openAccount;
    }

    public boolean isPhoneNumber() {
        return type == ACTIVE_TYPE_PHONE_NUMBER;
    }

    public Phone getPhone() {
        if (phone == null) {
            phone = new Gson().fromJson(body, Phone.class);
        }
        return phone;
    }
}
